package servlet;

import domain.Emp;
import service.EmpServiceImp;
import utils.Page;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class EmpListServlet extends HttpServlet {
    private EmpServiceImp empServiceImp=new EmpServiceImp();
    /*
    * 分页查询
    * */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      //接收页面传过来的请求参数 ，当前页，如果没有传 ，默认第一页

        //每页默认显示10条  这里设置死
        int pageSize=10;
        //当前页
        int pageCode=1;
        //接收请求参数
        String spageCode = request.getParameter("pageCode");
        //判断null  和 ""
        if(spageCode!=null&& !spageCode.trim().isEmpty()){
            //把spageCode  转换成整行
            pageCode=Integer.parseInt(spageCode);
        }
        //调用Service
        Page<Emp> page=empServiceImp.selEmpPage(pageCode,pageSize);
        request.setAttribute("page",page);
        request.getRequestDispatcher("/pages/emplist.jsp").forward(request,response);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
